#define _CRT_SECURE_NO_WARNINGS 1
/*
		反转链表
*/

#include <stdio.h>


//Definition for singly-linked list.
struct ListNode 
{
    int val;
    struct ListNode *next;
 };
 
typedef struct ListNode ListNode;
struct ListNode* reverseList(struct ListNode* head)
{
    //如果head为空
    if (head == NULL)
    {
        return NULL;
    }

    //head不为空，进行头插
    ListNode* newhead = head;
    ListNode* newtail = head;
    head = head->next;//从第二个节点开始头插
    while (head)
    {
        ListNode* tmp = head->next;
        head->next = newhead;
        newhead = head;
        head = tmp;
    }
    newtail->next = NULL;
    return newhead;
}